#include "StdAfx.h"
#include "DwmMessageProxy.h"
#include "DwmForNet.h"

using namespace Xfrog::Windows::DWM;

DwmMessageProxy::DwmMessageProxy(::System::IntPtr ptr){
	this->hInstance = ptr;
	pin_ptr<::IntPtr> pin =& ptr;

	this->lastWndProc = 0;
}

DwmMessageProxy::DwmMessageProxy(::System::Object^ object){
	this->m_dwm = object;
	::IntPtr ptr = ::System::Runtime::InteropServices::Marshal::GetIUnknownForObject(this->m_dwm);
	pin_ptr<::IntPtr> pinptr =& ptr;

//	pin_ptr<::System::Object^> x = *this->m_dwm;
	this->lastWndProc = 0;
}

::System::Object^ DwmMessageProxy::GetDwmForNetInstance(){
	if( this->m_dwm!=nullptr ){
		return this->m_dwm;
	}else if (this->hInstance!=::IntPtr::Zero ){
		return ::System::Runtime::InteropServices::Marshal::GetUniqueObjectForIUnknown(this->hInstance);
	}else
		return nullptr;
}

void DwmMessageProxy::CompositionChanged(){
	::DwmForNet^ dwm =(DwmForNet^) this->GetDwmForNetInstance();
	if( dwm!=nullptr){
		dwm->CompositionChanged(nullptr,nullptr);
	}
}

void DwmMessageProxy::ColorChanged(int color,bool b){
	::DwmForNet^ dwm =(DwmForNet^) this->GetDwmForNetInstance();
	if( dwm!=nullptr){
		dwm->ColorChanged(nullptr, gcnew ::ColorChangedEventArgs(color,b));
	}
}

void DwmMessageProxy::NCRenderingChanged(bool b){
	::DwmForNet^ dwm =(DwmForNet^) this->GetDwmForNetInstance();
	if( dwm!=nullptr){
		dwm->NCRenderingChanged(b);
	}
}

void DwmMessageProxy::MaximizedChanged(bool b){
	::DwmForNet^ dwm =(DwmForNet^) this->GetDwmForNetInstance();
	if( dwm!=nullptr){
		dwm->MaximizedChanged(b);
	}
}

bool DwmMessageProxy::BlurBehindProc(){
	::DwmForNet^ dwm =(DwmForNet^) this->m_dwm;
	if( dwm!=nullptr){
		return dwm->BlurPaintProc();
	}
	return false;
}